package com.ele.Servlet;

import cn.hutool.core.date.DateUtil;
import com.ele.Pojo.Shop;
import com.ele.Service.ShopService;
import com.ele.Service.impl.ShopServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/shopAdd")
public class ShopAddServlet extends HttpServlet {
    private ShopService shopService = new ShopServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        // 获取提交的数据
        String shopName = req.getParameter("shopName");
        String shopAddress = req.getParameter("shopAddress");
        String shopImg = req.getParameter("shopImg");
        String shopCategoryId = req.getParameter("shopCategoryId");
        String startTime = req.getParameter("startTime");
        String endTime = req.getParameter("endTime");
        String startPrice = req.getParameter("startPrice");
        String deliveryPrice = req.getParameter("deliveryPrice");
        String remarks = req.getParameter("remarks");
        String shopExplain = req.getParameter("shopExplain");
        String businessId = req.getParameter("businessId");
        Shop shop = new Shop();
        shop.setShopName(shopName);
        shop.setShopAddress(shopAddress);
        shop.setShopImg(shopImg);
        // 需要将字符串格式店铺分类id转成Integer类型
        shop.setShopCategoryId(Integer.valueOf(shopCategoryId));
        // 需要将字符串格式的日期数据转成Date类型
        shop.setStartTime(DateUtil.parse(startTime));
        shop.setEndTime(DateUtil.parse(endTime));
        shop.setStartPrice(Double.valueOf(startPrice));
        shop.setDeliveryPrice(Double.valueOf(deliveryPrice));
        shop.setRemarks(remarks);
        shop.setBusinessId(Integer.valueOf(businessId));
        shop.setShopExplain(shopExplain);
        Integer x = shopService.shopAdd(shop);
        resp.getWriter().write(x+"");

    }

}
